#include "Shape.h"
#include "ShapeGenerator.h"
#include<iostream>
using namespace std;

//copy c'tor
Shape::Shape(Shape &other)
{
	m_point.setX(other.getX());
	m_point.setY(other.getY());
	m_shiftX = other.getShiftX();
	m_shiftY = other.getShiftY();
	m_shiftXTmp = other.getShiftXTmp();
	m_shiftYTmp = other.getShiftYTmp();
}

void Shape::assignAnimationValues()
{
	double tmp;

	cout << "Enter shift x: ";
	cin >> tmp;
	if( tmp < -1 || tmp > 1)
	{
		cerr << "x shift value must be between 1 and -1";
		return;
	}
	m_shiftX = tmp;

	cout << "Enter shift Y: ";
	cin >> tmp;
	if( tmp < -1 || tmp > 1)
	{
		cerr << "y shift value must be between 1 and -1";
		return;
	}
	m_shiftY = tmp;
}

void Shape::moveShape()
{
	int shiftX,shiftY;
	cout << "enter shift for x coordinate (integer): ";
	cin >> shiftX;
	cout << "enter shift for y coordinate (integer): ";
	cin >> shiftY;

	m_point.setPoint(m_point.getX() + shiftX, m_point.getY() + shiftY);
}

void Shape::setPoint()
{
	int tmp_x,tmp_y;
	cin >> tmp_x >> tmp_y;
	setX(tmp_x);
	setY(tmp_y);
}

void Shape::saveType( ofstream &out_file, bool binary)
{
	ShapeGenerator::ShapeType type = ShapeGenerator::getType(this);
	if(binary)
		out_file.write( (const char*)&type, sizeof(ShapeGenerator::ShapeType));
	else //text
		out_file << type;
}

void Shape::save( ofstream &out_file, bool binary)
{
	saveType(out_file,binary);
	m_point.savePoint(out_file,binary);

	if(binary)
	{
		out_file.write( (const char*)&m_shiftX, sizeof(double) );
		out_file.write( (const char*)&m_shiftY, sizeof(double) );
	}
	else
		out_file << m_shiftX << " " << m_shiftY << " ";
	//out_file << (*this);
}